home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / gamekit-1 / HighScoreDistributor.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  35 lines

  1.  
  2. #import <appkit/appkit.h>
  3. #import <gamekit/gamekit.h>
  4. #import <remote/NXConnection.h>
  5. #import <objc/HashTable.h>
  6.  
  7. #define name "DAYHighScoreServer"
  8.  
  9. @implementation HighScoreDistributor
  10.  
  11. - init
  12. {
  13.     [super init];
  14.     servers = [[HashTable alloc] initKeyDesc:"*" valueDesc:"@" capacity:0];
  15.     return self;
  16. }
  17.  
  18. - getServerFor:(const char *)gameName
  19. {    // all we do is maintain a hash table that uses the name of the server
  20.     // as a key.  If the server is in the hash table, we return it.  If it
  21.     // isn't in the table, then we create a new server and return it.
  22.     id newServer, temp;
  23.     if ([servers isKey:gameName]) return [servers valueForKey:gameName];
  24.     newServer = [[HighScoreServer alloc] initForGame:gameName];
  25.     temp = [servers insertKey:gameName value:newServer];
  26.     if (temp) { // server existed.  Shouldn't get here if that was the case;
  27.         // if we _do_ get here, it's a bug in NeXT's HashTable!
  28.         fprintf(stderr, "%s: Just blew away the %s server!\n",
  29.                 name, [temp gameName]);
  30.         [[temp save] free];
  31.     }
  32.     return newServer;
  33. }
  34.  
  35. @end